import java.util.Arrays;

public class TestDemo {

    public static void func1(int[] array) {
        array = new int[] {24, 567, 26};
    }

    public static void func2(int[] array) {
        array[0] = 200;
    }

    public static void main(String[] args) {
        int[] array1 = {1, 2, 3, 4, 5};
        func1(array1);
        System.out.println(Arrays.toString(array1)); // 1, 2, 3, 4, 5

        int[] array2 = {6, 7, 8, 9, 10};
        func2(array2);
        System.out.println(Arrays.toString(array2)); // 200, 7, 8, 9, 10
    }



    public static void func() {
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;

        int[] array2 = new int[]{1,2,3,4,5};
        array2[0] = 100;
        array2[1] = 200;

        array1 = array2;
        array1[2] = 300;
        array1[3] = 400;
        array2[4] = 500;
        for (int i = 0; i < array2.length; i++) {
            System.out.println(array2[i]);
        }
    }

    public static void bubble(int[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            boolean flg = false;
            for (int j = 0; j < arr.length-1-i; j++) {
                if (arr[j] > arr[j+1]) {
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                    flg = true;
                }
            }
            if (flg == false) {
                break;
            }
        }
    }

    public static void main4(String[] args) {
        int[] arr = {8,29,46,1,49,28};
        bubble(arr);
        System.out.println(Arrays.toString(arr));
    }

    // 1 2  3 4 5
    // l    m   r
    public static int binary(int[] arr, int key) {
        int left = 0;
        int right = arr.length;
        while (left <= right) {
            int mid = (left + right) >>> 1;
            if (key < arr[mid]) {
                right = mid - 1;
            }else if (key == arr[mid]) {
                return mid;
            }else {
                left = mid + 1;
            }
        }
        return -1;
    }

    public static void main3(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        int index = binary(arr, 5);
        System.out.println(index);
    }

    public static void main2(String[] args) {
        int[][] array1 = {{1, 2, 3}, {4, 5, 6}};
        int[][] array2 = new int[][]{{1, 2, 3}, {4, 5, 6}};
        int[][] array3 = new int[2][3];

    }

    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5,6};
        int[] ret = Arrays.copyOfRange(array,1,3);
        System.out.println(Arrays.toString(ret));
    }
}
